#!/usr/bin/env python
# Copyright(c) 2010 Nuttachat Wisittipanit. All rights reserved.

from PyQt4.QtCore import (SIGNAL,QSettings,QVariant)
from PyQt4.QtGui import (QApplication,QMainWindow)

from mahbo.main.widgets import ui_main
#from mahbo.minings.clustering.som import som

#import time

#from QApplication.setApplicationName
applicationName     = QApplication.applicationName
#from QApplication.setApplicationVersion
applicationVersion  = QApplication.applicationVersion

#class FLOW(object):
#    def __init__(self,**kwargs):
#        self.REdatafact     = False
#        self.REsvm          = False
#        self.REmstat        = False
#        self.__dict__.update(kwargs)

class MAHBOWindow(QMainWindow, ui_main.Ui_MAHBOWindow):

    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.setConnect()
        settings = QSettings()
        self.restoreGeometry(settings.value("MainWindow/Geometry").toByteArray())
        self.restoreGeometry(settings.value("MainWindow/State").toByteArray())
        self.setWindowTitle("%s %s" % (applicationName(),applicationVersion()) )
#        print("sleep")
#        time.sleep(5)
    def setConnect(self):
        self.connect(self.actionSOM,SIGNAL("triggered()"),self.launchSOM)
        
    def launchSOM(self):
        pass
#        form = som.SOMDialog(parent = self)
#        if form.exec_():
#            pass
        
    def okToContinue(self):
        return True
    
    def closeEvent(self,event):
        #event is QCloseEvent
        if self.okToContinue():
            settings     = QSettings() #QSetting class only reads and writes QVariant objects
            settings.setValue("MainWindow/Geometry", QVariant(
                              self.saveGeometry())) #save size and position
            settings.setValue("MainWindow/State", QVariant(
                              self.saveState())) #save saveState (size,position,toolbar positions)
            event.accept() #The event is accepted and the widget is closed
        else:
            event.ignore() #Discard the close event and to leave the application running

